home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / stevie.arc / UNIX.C < prev   
C/C++ Source or Header  |  1990-01-10  |  2KB  |  168 lines

  1. /*
  2.  * System-dependent routines for UNIX System V Release 3.
  3.  */
  4.  
  5. #include "stevie.h"
  6. #include <termio.h>
  7.  
  8. /*
  9.  * inchar() - get a character from the keyboard
  10.  */
  11. int
  12. inchar()
  13. {
  14.     char    c;
  15.  
  16.     flushbuf();        /* flush any pending output */
  17.  
  18.     while (read(0, &c, 1) != 1)
  19.         ;
  20.  
  21.     return c;
  22. }
  23.  
  24. #define    BSIZE    2048
  25. static    char    outbuf[BSIZE];
  26. static    int    bpos = 0;
  27.  
  28. flushbuf()
  29. {
  30.     if (bpos != 0)
  31.         write(1, outbuf, bpos);
  32.     bpos = 0;
  33. }
  34.  
  35. /*
  36.  * Macro to output a character. Used within this file for speed.
  37.  */
  38. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  39.  
  40. /*
  41.  * Function version for use outside this file.
  42.  */
  43. void
  44. outchar(c)
  45. register char    c;
  46. {
  47.     outbuf[bpos++] = c;
  48.     if (bpos >= BSIZE)
  49.         flushbuf();
  50. }
  51.  
  52. void
  53. outstr(s)
  54. register char    *s;
  55. {
  56.     while (*s) {
  57.         outone(*s++);
  58.     }
  59. }
  60.  
  61. void
  62. beep()
  63. {
  64.     outone('\007');
  65. }
  66.  
  67. /*
  68.  * remove(file) - remove a file
  69.  */
  70. void
  71. remove(file)
  72. char *file;
  73. {
  74.     unlink(file);
  75. }
  76.  
  77. /*
  78.  * rename(of, nf) - rename existing file 'of' to 'nf'
  79.  */
  80. void
  81. rename(of, nf)
  82. char    *of, *nf;
  83. {
  84.     unlink(nf);
  85.     link(of, nf);
  86.     unlink(of);
  87. }
  88.  
  89. void
  90. delay()
  91. {
  92.     /* not implemented */
  93. }
  94.  
  95. static    struct    termio    ostate;
  96.  
  97. void
  98. windinit()
  99. {
  100.     char    *getenv();
  101.     char    *term;
  102.     struct    termio    nstate;
  103.  
  104.     if ((term = getenv("TERM")) == NULL || strcmp(term, "vt100") != 0) {
  105.         fprintf(stderr, "Invalid terminal type '%s'\n", term);
  106.         exit(1);
  107.     }
  108.     Columns = 80;
  109.     P(P_LI) = Rows = 24;
  110.  
  111.     /*
  112.      * Go into cbreak mode
  113.      */
  114.      ioctl(0, TCGETA, &ostate);
  115.      nstate = ostate;
  116.      nstate.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
  117.      nstate.c_cc[VMIN] = 1;
  118.      nstate.c_cc[VTIME] = 0;
  119.      ioctl(0, TCSETAW, &nstate);
  120. }
  121.  
  122. void
  123. windexit(r)
  124. int r;
  125. {
  126.     /*
  127.      * Restore terminal modes
  128.      */
  129.     ioctl(0, TCSETAW, &ostate);
  130.  
  131.     exit(r);
  132. }
  133.  
  134. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  135.  
  136. void
  137. windgoto(r, c)
  138. register int    r, c;
  139. {
  140.     r += 1;
  141.     c += 1;
  142.  
  143.     /*
  144.      * Check for overflow once, to save time.
  145.      */
  146.     if (bpos + 8 >= BSIZE)
  147.         flushbuf();
  148.  
  149.     outbuf[bpos++] = '\033';
  150.     outbuf[bpos++] = '[';
  151.     if (r >= 10)
  152.         outbuf[bpos++] = r/10 + '0';
  153.     outbuf[bpos++] = r%10 + '0';
  154.     outbuf[bpos++] = ';';
  155.     if (c >= 10)
  156.         outbuf[bpos++] = c/10 + '0';
  157.     outbuf[bpos++] = c%10 + '0';
  158.     outbuf[bpos++] = 'H';
  159. }
  160.  
  161. FILE *
  162. fopenb(fname, mode)
  163. char    *fname;
  164. char    *mode;
  165. {
  166.     return fopen(fname, mode);
  167. }
  168.